<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Ribbon | Hexo</title>
  <meta name="keywords" content=" Spring Cloud Alibaba ">
  <meta name="description" content="Ribbon | Hexo">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="description" content="如何解决消息过期失效问题RabbtiMQ 是可以设置过期时间的，也就是 TTL。如果消息在 queue 中积压超过一定的时间就会被 RabbitMQ 给清理掉，这个数据就没了。这就是说数据不会大量积压在 mq 里，而是大量的数据会直接搞丢。解决方法就是采用批量重导。 批量重导，也就是后期的一种手动补偿手段。当高峰期过去之后将丢失的那部分数据，写个临时程序查出来，重新放到MQ里，把白天的数据补回来。">
<meta property="og:type" content="article">
<meta property="og:title" content="Rabbit MQ（面试）">
<meta property="og:url" content="https://xiaomaer-sss.gitee.io/xiaomaer-sss/2023/02/03/Rabbit%20MQ%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="如何解决消息过期失效问题RabbtiMQ 是可以设置过期时间的，也就是 TTL。如果消息在 queue 中积压超过一定的时间就会被 RabbitMQ 给清理掉，这个数据就没了。这就是说数据不会大量积压在 mq 里，而是大量的数据会直接搞丢。解决方法就是采用批量重导。 批量重导，也就是后期的一种手动补偿手段。当高峰期过去之后将丢失的那部分数据，写个临时程序查出来，重新放到MQ里，把白天的数据补回来。">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2023-02-03T13:04:21.063Z">
<meta property="article:modified_time" content="2023-02-04T03:42:41.460Z">
<meta property="article:author" content="kiwi">
<meta property="article:tag" content="队列">
<meta property="article:tag" content="异步">
<meta name="twitter:card" content="summary">


<link rel="icon" href="/img/avatar.jpg">

<link href="/css/style.css?v=1.1.0" rel="stylesheet">

<link href="/css/hl_theme/atom-light.css?v=1.1.0" rel="stylesheet">

<link href="//cdn.jsdelivr.net/npm/animate.css@4.1.0/animate.min.css" rel="stylesheet">

<script src="//cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>
<script src="/js/titleTip.js?v=1.1.0" ></script>

<script src="//cdn.jsdelivr.net/npm/highlightjs@9.16.2/highlight.pack.min.js"></script>
<script>
    hljs.initHighlightingOnLoad();
</script>

<script src="//cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.js"></script>



<script src="//cdn.jsdelivr.net/npm/jquery.cookie@1.4.1/jquery.cookie.min.js" ></script>

<script src="/js/iconfont.js?v=1.1.0" ></script>

<meta name="generator" content="Hexo 5.4.2"></head>
<div style="display: none">
  <input class="theme_disqus_on" value="false">
  <input class="theme_preload_comment" value="">
  <input class="theme_blog_path" value="">
  <input id="theme_shortcut" value="true" />
  <input id="theme_highlight_on" value="true" />
  <input id="theme_code_copy" value="true" />
</div>



<body>
<aside class="nav">
    <div class="nav-left">
        <a href="/"
   class="avatar_target">
    <img class="avatar"
         src="/img/avatar.jpg"/>
</a>
<div class="author">
    <span>kiwi</span>
</div>

<div class="icon">
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
    
        
            <a title="csdn"
               href="https://blog.csdn.net/weixin_45340300?type=blog"
               target="_blank">
                
                    <svg class="iconfont-svg" aria-hidden="true">
                        <use xlink:href="#icon-csdn"></use>
                    </svg>
                
            </a>
        
    
        
    
        
    
        
            <a title="email"
               href="mailto:jackma.h@foxmail.com"
               target="_blank">
                
                    <svg class="iconfont-svg" aria-hidden="true">
                        <use xlink:href="#icon-email"></use>
                    </svg>
                
            </a>
        
    
        
            <a title="qq"
               href="http://wpa.qq.com/msgrd?v=3&uin=761791958&site=qq&menu=yes"
               target="_blank">
                
                    <svg class="iconfont-svg" aria-hidden="true">
                        <use xlink:href="#icon-qq"></use>
                    </svg>
                
            </a>
        
    
        
    
        
    
</div>




<ul>
    <li>
        <div class="all active" data-rel="All">All
            
                <small>(34)</small>
            
        </div>
    </li>
    
        
            
                <li>
                    <div data-rel="开发">
                        <i class="fold iconfont icon-right"></i>
                        
                        开发
                        <small>(34)</small>
                        
                    </div>
                    
                        <ul class="sub hide">
                            
                                <li>
                                    <div data-rel="开发<--->框架">
                                        
                                        框架
                                        
                                            <small>(14
                                                )</small>
                                        
                                    </div>
                                    
                                </li>
                            
                                <li>
                                    <div data-rel="开发<--->其他">
                                        
                                        其他
                                        
                                            <small>(5
                                                )</small>
                                        
                                    </div>
                                    
                                </li>
                            
                                <li>
                                    <div data-rel="开发<--->数据库">
                                        
                                        数据库
                                        
                                            <small>(2
                                                )</small>
                                        
                                    </div>
                                    
                                </li>
                            
                                <li>
                                    <div data-rel="开发<--->疑难杂症">
                                        
                                        疑难杂症
                                        
                                            <small>(2
                                                )</small>
                                        
                                    </div>
                                    
                                </li>
                            
                                <li>
                                    <div data-rel="开发<--->中间件">
                                        
                                        中间件
                                        
                                            <small>(5
                                                )</small>
                                        
                                    </div>
                                    
                                </li>
                            
                                <li>
                                    <div data-rel="开发<--->Java">
                                        
                                        Java
                                        
                                            <small>(6
                                                )</small>
                                        
                                    </div>
                                    
                                </li>
                            
                        </ul>
                    
                </li>
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
</ul>
<div class="left-bottom">
    <div class="menus">
        
            
            
            
    </div>
    <div>
        
        
    </div>
</div>
<input type="hidden" id="yelog_site_posts_number" value="34">
<input type="hidden" id="yelog_site_word_count" value="83.6k">
<div style="display: none">
    <span id="busuanzi_value_site_uv"></span>
    <span id="busuanzi_value_site_pv"></span>
</div>

    </div>
    <div class="nav-right">
        <div class="friends-area">
    <div class="friends-title">
        Links
        <i class="iconfont icon-left"></i>
    </div>
    <div class="friends-content">
        <ul>
            
            <li><a target="_blank" href="https://xiaomaer-sss.gitee.io/">叶落阁</a></li>
            
        </ul>
    </div>
</div>
        <div class="title-list">
    <div class="right-top">
        <div id="default-panel">
            <i class="iconfont icon-search" data-title="搜索 快捷键 i"></i>
            <div class="right-title">All</div>
            <i class="iconfont icon-file-tree" data-title="切换到大纲视图 快捷键 w"></i>
        </div>
        <div id="search-panel">
            <i class="iconfont icon-left" data-title="返回"></i>
            <input id="local-search-input" autocomplete="off"/>
            <label class="border-line" for="input"></label>
            <i class="iconfont icon-case-sensitive" data-title="大小写敏感"></i>
            <i class="iconfont icon-tag" data-title="标签"></i>
        </div>
        <div id="outline-panel" style="display: none">
            <div class="right-title">大纲</div>
            <i class="iconfont icon-list" data-title="切换到文章列表"></i>
        </div>
    </div>

    <div class="tags-list">
    <input id="tag-search" />
    <div class="tag-wrapper">
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>队列</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>分布式</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>缓存</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>流式处理</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>区块链</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>实战面试题</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>数据库</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>异步</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Bug</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Docker</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Java</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Java-集合</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Java-进阶</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Java-JVM</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Java基础</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>LB</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>MQ</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Mybatis</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>MySQL</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Redis</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Spring</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>Spring Cloud Alibaba</a>
            </li>
        
            <li class="article-tag-list-item">
                <i class="iconfont icon-tag"></i><a>SpringBoot</a>
            </li>
        
    </div>

</div>

    
    <nav id="title-list-nav">
        
        
        <a  class="All 开发 中间件 "
           href="/xiaomaer-sss/2023/02/03/Rabbit%20MQ%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="队列,异步"
           data-author="" >
            <span class="post-title" title="Rabbit MQ（面试）">Rabbit MQ（面试）</span>
            <span class="post-date" title="2023-02-03 21:04:21">2023/02/03</span>
        </a>
        
        
        <a  class="All 开发 Java "
           href="/xiaomaer-sss/2023/02/03/%E5%AE%9E%E6%88%98%E9%9D%A2%E8%AF%95%E9%A2%98%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="实战面试题"
           data-author="" >
            <span class="post-title" title="实战面试题">实战面试题</span>
            <span class="post-date" title="2023-02-03 17:11:07">2023/02/03</span>
        </a>
        
        
        <a  class="All 开发 中间件 "
           href="/xiaomaer-sss/2023/02/02/Kafka%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="分布式,流式处理,MQ"
           data-author="" >
            <span class="post-title" title="Kafka（面试）">Kafka（面试）</span>
            <span class="post-date" title="2023-02-02 09:51:06">2023/02/02</span>
        </a>
        
        
        <a  class="All 开发 中间件 "
           href="/xiaomaer-sss/2023/02/02/Zookeeper%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="分布式"
           data-author="" >
            <span class="post-title" title="Zookeeper（面试）">Zookeeper（面试）</span>
            <span class="post-date" title="2023-02-02 09:50:33">2023/02/02</span>
        </a>
        
        
        <a  class="All 开发 中间件 "
           href="/xiaomaer-sss/2023/02/01/Redis%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="Redis,缓存"
           data-author="" >
            <span class="post-title" title="Redis（面试）">Redis（面试）</span>
            <span class="post-date" title="2023-02-01 14:09:09">2023/02/01</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/30/SpringBoot%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="SpringBoot"
           data-author="" >
            <span class="post-title" title="SpringBoot（面试）">SpringBoot（面试）</span>
            <span class="post-date" title="2023-01-30 20:26:42">2023/01/30</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/30/Mybatis%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="Mybatis"
           data-author="" >
            <span class="post-title" title="Mybatis（面试）">Mybatis（面试）</span>
            <span class="post-date" title="2023-01-30 19:13:44">2023/01/30</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/30/Spring%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="Spring"
           data-author="" >
            <span class="post-title" title="Spring（面试）">Spring（面试）</span>
            <span class="post-date" title="2023-01-30 19:12:30">2023/01/30</span>
        </a>
        
        
        <a  class="All 开发 Java "
           href="/xiaomaer-sss/2023/01/29/Java-JVM%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="Java-JVM"
           data-author="" >
            <span class="post-title" title="Java-JVM（面试）">Java-JVM（面试）</span>
            <span class="post-date" title="2023-01-29 16:31:34">2023/01/29</span>
        </a>
        
        
        <a  class="All 开发 Java "
           href="/xiaomaer-sss/2023/01/29/Java-%E8%BF%9B%E9%98%B6%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="Java-进阶"
           data-author="" >
            <span class="post-title" title="Java-进阶（面试）">Java-进阶（面试）</span>
            <span class="post-date" title="2023-01-29 13:11:10">2023/01/29</span>
        </a>
        
        
        <a  class="All 开发 Java "
           href="/xiaomaer-sss/2023/01/29/Java-%E9%9B%86%E5%90%88%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="Java-集合"
           data-author="" >
            <span class="post-title" title="Java-集合（面试）">Java-集合（面试）</span>
            <span class="post-date" title="2023-01-29 09:18:51">2023/01/29</span>
        </a>
        
        
        <a  class="All 开发 数据库 "
           href="/xiaomaer-sss/2023/01/28/%E6%95%B0%E6%8D%AE%E5%BA%93-MySQL%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="MySQL"
           data-author="" >
            <span class="post-title" title="数据库-MySQL（面试）">数据库-MySQL（面试）</span>
            <span class="post-date" title="2023-01-28 16:50:59">2023/01/28</span>
        </a>
        
        
        <a  class="All 开发 Java "
           href="/xiaomaer-sss/2023/01/27/Java-%E5%9F%BA%E7%A1%80%EF%BC%88%E9%9D%A2%E8%AF%95%EF%BC%89/"
           data-tag="Java基础"
           data-author="" >
            <span class="post-title" title="Java-基础（面试）">Java-基础（面试）</span>
            <span class="post-date" title="2023-01-27 19:42:58">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 其他 "
           href="/xiaomaer-sss/2023/01/27/%E5%8C%BA%E5%9D%97%E9%93%BE%E9%92%B1%E5%8C%85/"
           data-tag="区块链"
           data-author="" >
            <span class="post-title" title="区块链钱包">区块链钱包</span>
            <span class="post-date" title="2023-01-27 18:57:51">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 其他 "
           href="/xiaomaer-sss/2023/01/27/Truffle%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/"
           data-tag="区块链"
           data-author="" >
            <span class="post-title" title="Truffle常用命令&amp;Web3常用方法">Truffle常用命令&amp;Web3常用方法</span>
            <span class="post-date" title="2023-01-27 18:57:51">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 其他 "
           href="/xiaomaer-sss/2023/01/27/Truffle&OpenZeppelin%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/"
           data-tag="区块链"
           data-author="" >
            <span class="post-title" title="Truffle&amp;OpenZeppelin环境搭建">Truffle&amp;OpenZeppelin环境搭建</span>
            <span class="post-date" title="2023-01-27 18:57:51">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 其他 "
           href="/xiaomaer-sss/2023/01/27/Solidity/"
           data-tag="区块链"
           data-author="" >
            <span class="post-title" title="Solidity">Solidity</span>
            <span class="post-date" title="2023-01-27 18:57:51">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 中间件 "
           href="/xiaomaer-sss/2023/01/27/Nginx/"
           data-tag="LB"
           data-author="" >
            <span class="post-title" title="Nginx">Nginx</span>
            <span class="post-date" title="2023-01-27 18:57:51">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/27/DockerFile/"
           data-tag="Docker"
           data-author="" >
            <span class="post-title" title="Dockerfile">Dockerfile</span>
            <span class="post-date" title="2023-01-27 17:45:23">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 其他 "
           href="/xiaomaer-sss/2023/01/27/%E5%8C%BA%E5%9D%97%E9%93%BE%E4%B9%8B%E4%BB%A5%E5%A4%AA%E5%9D%8A/"
           data-tag="区块链"
           data-author="" >
            <span class="post-title" title="区块链之以太坊">区块链之以太坊</span>
            <span class="post-date" title="2023-01-27 17:45:23">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 数据库 "
           href="/xiaomaer-sss/2023/01/27/%E5%B8%B8%E7%94%A8SQL%E8%AF%AD%E6%B3%95%E6%95%B4%E7%90%86/"
           data-tag="MySQL,数据库"
           data-author="" >
            <span class="post-title" title="常用SQL语法整理">常用SQL语法整理</span>
            <span class="post-date" title="2023-01-27 17:45:23">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/27/docker%E8%BF%9B%E9%98%B6/"
           data-tag="Docker"
           data-author="" >
            <span class="post-title" title="Docker进阶">Docker进阶</span>
            <span class="post-date" title="2023-01-27 17:45:23">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/27/Docker%E5%9F%BA%E7%A1%80/"
           data-tag="Docker"
           data-author="" >
            <span class="post-title" title="Docker基础">Docker基础</span>
            <span class="post-date" title="2023-01-27 17:45:23">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/27/Docker%E5%AE%89%E8%A3%85%E5%B8%B8%E8%A7%81%E7%BB%84%E4%BB%B6/"
           data-tag="Docker"
           data-author="" >
            <span class="post-title" title="Docker安装常见组件">Docker安装常见组件</span>
            <span class="post-date" title="2023-01-27 17:45:23">2023/01/27</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/26/SkyWalking/"
           data-tag="Spring Cloud Alibaba"
           data-author="" >
            <span class="post-title" title="SkyWalking">SkyWalking</span>
            <span class="post-date" title="2023-01-26 21:39:44">2023/01/26</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/26/Sentinel/"
           data-tag="Spring Cloud Alibaba"
           data-author="" >
            <span class="post-title" title="Sentinel">Sentinel</span>
            <span class="post-date" title="2023-01-26 21:39:44">2023/01/26</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/26/Seata/"
           data-tag="Spring Cloud Alibaba"
           data-author="" >
            <span class="post-title" title="Seata">Seata</span>
            <span class="post-date" title="2023-01-26 21:39:44">2023/01/26</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/26/Ribbon/"
           data-tag="Spring Cloud Alibaba"
           data-author="" >
            <span class="post-title" title="Ribbon">Ribbon</span>
            <span class="post-date" title="2023-01-26 21:39:44">2023/01/26</span>
        </a>
        
        
        <a  class="All 开发 疑难杂症 "
           href="/xiaomaer-sss/2023/01/26/github%E6%8B%89%E5%8F%96%E4%BB%A3%E7%A0%81%E6%8A%A5%20git@github.com's%20password/"
           data-tag="Bug"
           data-author="" >
            <span class="post-title" title="github拉取代码报 &#34;git@github.com&#39;s password&#34;">github拉取代码报 &#34;git@github.com&#39;s password&#34;</span>
            <span class="post-date" title="2023-01-26 21:39:44">2023/01/26</span>
        </a>
        
        
        <a  class="All 开发 疑难杂症 "
           href="/xiaomaer-sss/2023/01/26/gitee%E6%90%AD%E5%BB%BA%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2%E6%95%99%E7%A8%8B/"
           data-tag="Bug"
           data-author="" >
            <span class="post-title" title="gitee搭建个人博客教程">gitee搭建个人博客教程</span>
            <span class="post-date" title="2023-01-26 21:39:44">2023/01/26</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/26/GateWay/"
           data-tag="Spring Cloud Alibaba"
           data-author="" >
            <span class="post-title" title="GateWay">GateWay</span>
            <span class="post-date" title="2023-01-26 21:39:44">2023/01/26</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/26/Fegin/"
           data-tag="Spring Cloud Alibaba"
           data-author="" >
            <span class="post-title" title="Fegin">Fegin</span>
            <span class="post-date" title="2023-01-26 21:39:44">2023/01/26</span>
        </a>
        
        
        <a  class="All 开发 框架 "
           href="/xiaomaer-sss/2023/01/20/Nacos/"
           data-tag="Spring Cloud Alibaba"
           data-author="" >
            <span class="post-title" title="Nacos">Nacos</span>
            <span class="post-date" title="2023-01-20 17:12:00">2023/01/20</span>
        </a>
        
        
        <a  class="All 开发 Java "
           href="/xiaomaer-sss/2023/01/17/hello-world/"
           data-tag="Java"
           data-author="" >
            <span class="post-title" title="Hello World">Hello World</span>
            <span class="post-date" title="2023-01-17 15:40:39">2023/01/17</span>
        </a>
        
        <div id="no-item-tips">

        </div>
    </nav>
    <div id="outline-list">
    </div>
</div>

    </div>
    <div class="hide-list">
        <div class="semicircle" data-title="切换全屏 快捷键 s">
            <div class="brackets first"><</div>
            <div class="brackets">&gt;</div>
        </div>
    </div>
</aside>
<div id="post">
    <div class="pjax">
        <article id="post-Ribbon" class="article article-type-post" itemscope itemprop="blogPost">
    
        <h1 class="article-title">Ribbon</h1>
    
    <div class="article-meta">
        
        
        
        <span class="book">
            <i class="iconfont icon-category"></i>
            
            
            <a  data-rel="开发">开发</a> > 
            
            <a  data-rel="开发&lt;---&gt;框架">框架</a>
            
        </span>
        
        
        <span class="tag">
            <i class="iconfont icon-tag"></i>
            
            <a class="color1">Spring Cloud Alibaba</a>
            
        </span>
        
    </div>
    <div class="article-meta">
        
            Created At : <time class="date" title='Updated At: 2023-01-26 22:02:58'>2023-01-26 21:39</time>
        
    </div>
    <div class="article-meta">
        
        <span>Count:899</span>
        
        
        <span id="busuanzi_container_page_pv">
            Views 👀 :<span id="busuanzi_value_page_pv">
                <span class="count-comment">
                    <span class="spinner">
                      <div class="cube1"></div>
                      <div class="cube2"></div>
                    </span>
                </span>
            </span>
        </span>
        
        
    </div>
    
    <div class="toc-ref">
    
        <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#Load-Balance"><span class="toc-text">Load Balance</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AE%A2%E6%88%B7%E7%AB%AF%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1"><span class="toc-text">客户端负载均衡</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9C%8D%E5%8A%A1%E7%AB%AF%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1"><span class="toc-text">服务端负载均衡</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B8%B8%E8%A7%81%E7%9A%84%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E7%AE%97%E6%B3%95"><span class="toc-text">常见的负载均衡算法</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9%E9%BB%98%E8%AE%A4%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E7%AD%96%E7%95%A5"><span class="toc-text">修改默认负载均衡策略</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE%E7%B1%BB%E7%9A%84%E6%96%B9%E5%BC%8F"><span class="toc-text">配置类的方式</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8yml%E7%9A%84%E6%96%B9%E5%BC%8F%EF%BC%88%E6%8E%A8%E8%8D%90%EF%BC%89"><span class="toc-text">使用yml的方式（推荐）</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E5%99%A8"><span class="toc-text">自定义负载均衡器</span></a></li></ol>
    
<style>
    .left-col .switch-btn,
    .left-col .switch-area {
        display: none;
    }
    .toc-level-3 i,
    .toc-level-3 ol {
        display: none !important;
    }
</style>
</div>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>Spring cloud Ribbon 是基于Netflix Ribbon实现的一套客户端负载均衡的工具。主要功能是提供客户端的软件负载均衡算法和服务调用。Ribbon客户端组件提供一系列完善的配置，如连接超时，重试等。简单说就是在配置文件中列出Load Balancer（简称LB）后面所有的机器，Ribbon会自动的帮你基于某种规则去连接这些机器。同时我们可以很容易的使用Ribbon实现自定义的负载均衡算法。</p>
<h2 id="Load-Balance"><a href="#Load-Balance" class="headerlink" title="Load Balance"></a>Load Balance</h2><p>目前主流的LB分为两类：</p>
<ol>
<li>集中式LB<br>在服务消费方和提供方之间使用独立的LB设施（例如硬件F5，软件nginx）由该设施负责把访问请求通过某种策略转发至服务提供方。</li>
<li>进程内LB<br>将LB逻辑集成到消费方，消费方从服务注册中心获取服务消费提供方列表，然后自己从这些列表中根据某种规则选择一个合适的服务提供者。</li>
</ol>
<h2 id="客户端负载均衡"><a href="#客户端负载均衡" class="headerlink" title="客户端负载均衡"></a>客户端负载均衡</h2><p>客户端负载均衡是属于进程内LB的方法，即在客户端（服务消费者）有一个可用的服务器提供者列表，然后通过负载均衡算法选择一个服务提供者进行请求。名称就很见民之意，在客户端就进行负载均衡算法分配。</p>
<p><img src="https://gitee.com/xiaomaer-sss/picgo/raw/master/images/2023/1671257915451.png" alt="1671257915451"></p>
<h2 id="服务端负载均衡"><a href="#服务端负载均衡" class="headerlink" title="服务端负载均衡"></a>服务端负载均衡</h2><p>服务端负载均衡是属于集中式LB的方法。也就是在服务消费者和服务提供者之间架设设施（软件或者硬件）进行负载均衡的算法，在多个服务器之间选择一个进行访问。</p>
<p><img src="https://gitee.com/xiaomaer-sss/picgo/raw/master/images/2023/1671258533050.png" alt="1671258533050"></p>
<h2 id="常见的负载均衡算法"><a href="#常见的负载均衡算法" class="headerlink" title="常见的负载均衡算法"></a>常见的负载均衡算法</h2><ul>
<li>RoundRobinRule <strong>轮询</strong><br>可用服务列表中的服务进行循环选择</li>
<li>RandomRule <strong>随机</strong><br>随机获取一个服务进行访问</li>
<li>RetryRule <strong>重试</strong><br>如果获取服务失败则在指定时间内会进行重试获取</li>
<li>WeightedResponseTimeRule <strong>权重</strong><br>对轮询的扩展，响应平均速度越快的服务选择的权重越大，越容易被选择</li>
<li>BestAvailableRule <strong>最空闲策略</strong><br>选择一个最小的并发请求的服务</li>
<li>ZoneAvoidanceRule <strong>默认规则</strong><br>优先选择同一个区域的服务器</li>
</ul>
<h2 id="修改默认负载均衡策略"><a href="#修改默认负载均衡策略" class="headerlink" title="修改默认负载均衡策略"></a>修改默认负载均衡策略</h2><h3 id="配置类的方式"><a href="#配置类的方式" class="headerlink" title="配置类的方式"></a>配置类的方式</h3><p><strong>编写配置类</strong></p>
<p><strong>注意：</strong>这里的配置类要写在@ComponetScan扫描不到的地方，否则这个策略就是所有的RibbonClients所共享，对所有的调用服务生效。</p>
<p>@SpringbootApplication注解里面包含了@ComponentScan注解，要写在启动类的外面。</p>
<pre><code class="java">@Configuration
public class RibbonRandomRuleConfig &#123;

    @Bean
    public IRule iRule()&#123;
        return new RandomRule();
    &#125;

&#125;
</code></pre>
<p><strong>使用配置类</strong></p>
<p>在启动类上添加@RibbonClients注解</p>
<pre><code class="java">@SpringBootApplication
@EnableDiscoveryClient
//配置类的方式实现客户端负载均衡
@RibbonClients(value = &#123;
        @RibbonClient(name = &quot;stock-service&quot;, configuration = RibbonRandomRuleConfig.class)
&#125;)
public class OrderApplication &#123;
    public static void main(String[] args) &#123;
        SpringApplication.run(OrderApplication.class,args);
    &#125;
&#125;
</code></pre>
<h3 id="使用yml的方式（推荐）"><a href="#使用yml的方式（推荐）" class="headerlink" title="使用yml的方式（推荐）"></a>使用yml的方式（推荐）</h3><p>在配置文件中添加客户端负载均衡的配置即可</p>
<pre><code class="yml"># 配置的方式配置客户端负载均衡算法
stock-service:
  ribbon:
    NFLoadBalancerRuleClassName: com.alibaba.cloud.nacos.ribbon.NacosRule
ribbon:
  # 开启ribbon饥饿加载
  eager-load:
    enabled: true
    # 配置使用饥饿加载的服务名称，多个服务使用逗号分开
    clients: stock-service
</code></pre>
<h2 id="自定义负载均衡器"><a href="#自定义负载均衡器" class="headerlink" title="自定义负载均衡器"></a>自定义负载均衡器</h2><p>实现AbstractLoadBalancerRule，里面的核心方法是choose，自定义实现的时候要注意并发编程的问题。一般还是使用市面上比较稳定成熟的比较好。不建议自定义实现。</p>

      
       <hr><span style="font-style: italic;color: gray;"> 转载请注明来源，欢迎对文章中的引用来源进行考证，欢迎指出任何有错误或不够清晰的表达。可以邮件至 jackma.h@foxmail.com </span>
    </div>
</article>


<p>
    <a  class="dashang" onclick="dashangToggle()">💰</a>
</p>






    




    </div>
    <div class="copyright">
        <p class="footer-entry">
    ©2017 kiwi
</p>
<p class="footer-entry">Built with <a href="https://hexo.io/" target="_blank">Hexo</a> and <a href="https://github.com/yelog/hexo-theme-3-hexo" target="_blank">3-hexo</a> theme</p>

    </div>
    <div class="full-toc">
        <button class="full" data-title="切换全屏 快捷键 s"><span class="min "></span></button>
<a class="" id="rocket" ></a>

    </div>
</div>

<div class="hide_box" onclick="dashangToggle()"></div>
<div class="shang_box">
    <a class="shang_close"  onclick="dashangToggle()">×</a>
    <div class="shang_tit">
        <p>Help us with donation</p>
    </div>
    <div class="shang_payimg">
        <div class="pay_img">
            <img src="/img/alipay.jpg" class="alipay" title="扫码支持">
            <img src="/img/weixin.jpg" class="weixin" title="扫码支持">
        </div>
    </div>
    <div class="shang_payselect">
        <span><label><input type="radio" name="pay" checked value="alipay">alipay</label></span><span><label><input type="radio" name="pay" value="weixin">weixin</label></span>
    </div>
</div>


</body>
<script src="/js/jquery.pjax.js?v=1.1.0" ></script>

<script src="/js/script.js?v=1.1.0" ></script>
<script>
    var img_resize = 'default';
    function initArticle() {
        /*渲染对应的表格样式*/
        
            $("#post .pjax table").addClass("green_title");
        

        /*渲染打赏样式*/
        
        $("input[name=pay]").on("click", function () {
            if($("input[name=pay]:checked").val()=="weixin"){
                $(".shang_box .shang_payimg .pay_img").addClass("weixin_img");
            } else {
                $(".shang_box .shang_payimg .pay_img").removeClass("weixin_img");
            }
        })
        

        /*高亮代码块行号*/
        

        /*访问数量*/
        
        $.getScript("//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js");
        

        /*代码高亮，行号对齐*/
        $('.pre-numbering').css('line-height',$('.has-numbering').css('line-height'));

        
        
    }

    /*打赏页面隐藏与展示*/
    
    function dashangToggle() {
        $(".shang_box").fadeToggle();
        $(".hide_box").fadeToggle();
    }
    

</script>

<!--加入行号的高亮代码块样式-->

<!--自定义样式设置-->
<style>
    
    
    .nav {
        width: 542px;
    }
    .nav.fullscreen {
        margin-left: -542px;
    }
    .nav-left {
        width: 120px;
    }
    
    
    @media screen and (max-width: 1468px) {
        .nav {
            width: 492px;
        }
        .nav.fullscreen {
            margin-left: -492px;
        }
        .nav-left {
            width: 100px;
        }
    }
    
    
    @media screen and (max-width: 1024px) {
        .nav {
            width: 492px;
            margin-left: -492px
        }
        .nav.fullscreen {
            margin-left: 0;
        }
    }
    
    @media screen and (max-width: 426px) {
        .nav {
            width: 100%;
        }
        .nav-left {
            width: 100%;
        }
    }
    
    
    .nav-right .title-list nav a .post-title, .nav-right .title-list #local-search-result a .post-title {
        color: #383636;
    }
    
    
    .nav-right .title-list nav a .post-date, .nav-right .title-list #local-search-result a .post-date {
        color: #5e5e5f;
    }
    
    
    .nav-right nav a.hover, #local-search-result a.hover{
        background-color: #e2e0e0;
    }
    
    

    /*列表样式*/
    
    #post .pjax article .article-entry>ol, #post .pjax article .article-entry>ul, #post .pjax article>ol, #post .pjax article>ul{
        border: #e2dede solid 1px;
        border-radius: 10px;
        padding: 10px 32px 10px 56px;
    }
    #post .pjax article .article-entry li>ol, #post .pjax article .article-entry li>ul,#post .pjax article li>ol, #post .pjax article li>ul{
        padding-top: 5px;
        padding-bottom: 5px;
    }
    #post .pjax article .article-entry>ol>li, #post .pjax article .article-entry>ul>li,#post .pjax article>ol>li, #post .pjax article>ul>li{
        margin-bottom: auto;
        margin-left: auto;
    }
    #post .pjax article .article-entry li>ol>li, #post .pjax article .article-entry li>ul>li,#post .pjax article li>ol>li, #post .pjax article li>ul>li{
        margin-bottom: auto;
        margin-left: auto;
    }
    

    /* 背景图样式 */
    
    #post {
        background: url([object Object]);
    }
    
    
    #post .index {
        background: url([object Object]);
    }
    


    /*引用块样式*/
    

    /*文章列表背景图*/
    
    .nav-right:before {
        content: ' ';
        display: block;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        opacity: 0.3;
        background: url("https://i.loli.net/2019/07/22/5d3521411f3f169375.png");
        background-repeat: no-repeat;
        background-position: 50% 0;
        -ms-background-size: cover;
        -o-background-size: cover;
        -moz-background-size: cover;
        -webkit-background-size: cover;
        background-size: cover;
    }
    

    
</style>







</html>
